#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <unordered_map>

using namespace std;

class Solution 
{
    private:

        vector<int>number_of_R_and_U;
        unordered_map<int, vector<int>> Int_Vector_Two;

        void HandleCommand(string command)
        {
            vector<int>coordinate(2);
            int x = 0;
            int y = 0;
            int i = 0;
            
            coordinate[0] = x;
            coordinate[1] = y;
            Int_Vector_Two[i] = coordinate;
            for(auto it:command)
            {
                ++i;

                if(it == 'U')
                    y += 1;
                else if (it == 'R')
                    x += 1;
                
                coordinate[0] = x;
                coordinate[1] = y;
                Int_Vector_Two[i] = coordinate;
                
                
            }

            number_of_R_and_U.push_back(x);
            number_of_R_and_U.push_back(y);
            
            // return number_of_R_and_U;
        }

        int JudgeRresultInMapAndReturnN(int x, int y)
        {

            int the_count_of_R = number_of_R_and_U[0];
            int the_count_of_U = number_of_R_and_U[1];
            int nx = x / the_count_of_R;
            int ny = y / the_count_of_U;
            int n = nx < ny ? nx : ny;

            x = x - n * the_count_of_R;
            y = y - n * the_count_of_U;

            auto it = Int_Vector_Two.find(x + y);

            if(it == Int_Vector_Two.end())
                return -1;
            else if ((it->second[0] == x)&&(it ->second[1] == y))
                return n;
            else
                return -1;
            
            
   
        }

    public:

        bool robot(string command, vector<vector<int>>& obstacles, int x, int y) 
        {
            int result,pass;

            HandleCommand(command);
            //1.result must in hashmap, if not return 0
            result = JudgeRresultInMapAndReturnN(x, y);
            if(result == -1) return false;
            //2.calculation the number of x,y / R,U == n
            //3.calculation the number of xx/R = n1 and yy/U = n2
            for(auto it : obstacles)
            {
                pass = JudgeRresultInMapAndReturnN(it[0],it[1]);
                if((pass != -1)&&((it[0] + it[1]) <= (x + y)))
                    return false;
                
            }
            return true;
            
            //4.if n1 == n2 > n continue
            //5.if n1 != n2 return 0, else if n1, n2 != int return 0 pass
        }
};


int main()
{
    Solution A;
    vector<vector<int>> obstacles{{5,5},{9,4},{9,7},{6,4},{7,0},{9,5},{10,7},{1,1},{7,5}};
    // vector<int>coordinate(2);
    // for(auto it = coordinate.begin();it != coordinate.end();it++)
    // {
    //     *it = 2;
    // }
    // for(auto it : coordinate)
    // {
    //     it = 2;
    // }
    // obstacles.push_back(coordinate);
    
    cout<<A.robot("RRU",obstacles,1486,743);
    return 0;
}

